<template>
  <view class="page-user-info">
    <van-cell-group :border="false">
      <van-cell title="更换头像" size="large">
        <van-icon slot="right-icon" name="edit" />
        <button class="btn-avatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
          <van-image fit="cover" round width="60rpx" height="60rpx" class="img-aavatar" :src="avatar_url"/>
        </button> 
      </van-cell>
      <van-cell title="姓名" :value="form.username" size="large" />
      <van-cell title="手机号" :value="form.username" size="large" />
      <van-cell title="承运商" :value="form.username" size="large" />
      <van-cell title="级别" :value="form.username" size="large" />
    </van-cell-group>
    <view class="p-a-15">
      <!-- <van-button type="info" round block @tap="submitForm">保存</van-button> -->
      <van-button size="large" block @tap="loginOut">退出登录</van-button>
    </view>
  </view>
</template>

<script>
import uploadMixins from '@/static/mixins/upload';
export default {
  mixins: [uploadMixins],
  data(){
    return{
      form:{
        userId: null,
        username: null,
        avatar: null,
        name: null,
        phone: null,
      },
      avatar_url: null
    }
  },
  onShow(){
    this.getUserInfo();
  },
  methods:{
    getUserInfo(){
      this.$http('get', '/admin/user/info', {}, (data,msg) => {
        this.$utils.resetForm(this.form, data.sysUser);
        this.avatar_url = data.sysUser.avatar;
      }, msg => {},{}, 'noLoading')
    },
    onChooseAvatar(e) {
      let url = e.detail.avatarUrl;   
      this.handleUpload(url);
    },
    uploadSuccess(data){
      this.form.avatar = data.tempfileName;
      this.avatar_url = data.tempfilePath;
    },
    getName(e){
      this.form.name = e.detail.value;
    },
    verifyForm(){
      if(!this.$verify.null(this.form.avatar,'请上传头像')){
        return false;
      }
      if(!this.$verify.null(this.form.name, '请填写昵称')){
        return false;
      }
      if(!this.$verify.mobile(this.form.phone)){
        return false;
      }
      return true;
    },
    submitForm() {
      if(!this.verifyForm){
        return;
      }
      this.$http('put', '/admin/user', this.form, (data,msg) => {
        uni.showToast({title: '保存成功'});
        this.getUserInfo();
      });
		},
  }
}
</script>

<style lang="scss" scoped>
.img-avatar{margin-right:0;}
.btn-avatar{
  border:none;background:none;padding:0;margin:0;display:inline-block;height:64rpx;margin-right:10rpx;
  &:after{display:none;}
}
</style>